<%--
  Created by IntelliJ IDEA.
  User: benhailong
  Date: 2018/2/7
  Time: 下午3:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>添加品牌</title>
    <link rel="stylesheet" href="<%=basePath%>templates/style/plugins/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="<%=basePath%>templates/style/build/css/doc.css" media="all">
    <script src="<%=basePath%>templates/style/plugins/layui/layui.js"></script>
    <script src="<%=basePath%>templates/style/plugins/layui/jquery-3.3.1.min.js"></script>
</head>
<body>

    <div class="kit-doc">
        <form class="layui-form layui-form-pane" action="">

            <div class="layui-form-item">
                <label class="layui-form-label">品牌分类</label>
                <div class="layui-input-block">
                    <%--<input name="shopTypeStr" id="shopTypeStr" lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input" type="text">--%>
                    <input type="hidden" name="sbId" id="sbId" value="${kitModel.sbId}">
                    <select id="shopTypeStr" name="shopTypeStr">
                        <option value="-1">请选择</option>
                        <c:forEach items="${shopTypeModel}" var="stm">
                            <option value="${stm.stId}" <c:if test="${kitModel.stId==stm.stId}">selected="selected"</c:if>>${stm.stName}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>

            <div class="layui-form-item" >
                <label class="layui-form-label" style="height: 137px; line-height: 117px">品牌logo${kitModel.sbLogoUrl}</label>
                <input name="sbLogoUrl" id="imgurl" value="${kitModel.sbLogoUrl}" autocomplete="off" class="layui-input" type="hidden">
                <div class=" layui-upload-drag" id="img" style="border-left: 0px;">
                    <i class="layui-icon">&#xe654;</i>
                    <p>点击上传品牌logo</p>
                    <img id="demo1" style="position: absolute;height: 137px;width: 137px;margin: -106px auto auto -30px;" src="${kitModel.sbLogoUrl}"/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">品牌中文名</label>
                <div class="layui-input-block">
                    <input name="sbNameCn" id="sbNameCn" value="${kitModel.sbNameCn}" placeholder="请输入品牌中文名" autocomplete="off" class="layui-input" type="text">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">品牌英文名</label>
                <div class="layui-input-block">
                    <input name="sbNameEn" id="sbNameEn" value="${kitModel.sbNameEn}" placeholder="请输入品牌英文名" autocomplete="off" class="layui-input" type="text">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">品牌官网</label>
                <div class="layui-input-block">
                    <input name="sbWeb" id="sbWeb" value="${kitModel.sbWeb}" placeholder="请输入品牌官网" autocomplete="off" class="layui-input" type="text">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">品牌状态</label>
                <div class="layui-input-block">
                    <select name="sbType" id="sbType" lay-verify="required" lay-search="">
                        <option value="-1">请选择</option>
                        <option value="1" <c:if test="${kitModel.sbType==1}">selected="selected"</c:if>>可用</option>
                        <option value="2" <c:if test="${kitModel.sbType==2}">selected="selected"</c:if>>不可用</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">品牌描述</label>
                <div class="layui-input-block">
                    <%--<input name="sbDescribe"  lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input" type="password">--%>
                    <textarea id="sbDescribe" name="sbDescribe" maxlength="200" class="layui-textarea" cols="30" rows="5">${kitModel.sbDescribe}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">品牌故事</label>
                <div class="layui-input-block">
                    <%--<input name="sbDescribe"  lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input" type="password">--%>
                    <textarea id="sbOldPractice" name="sbOldPractice" maxlength="1000" class="layui-textarea" cols="30" rows="10">${kitModel.sbOldPractice}</textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <button class="layui-btn" lay-submit="" lay-filter="add">修改</button>
            </div>
        </form>

        <!--这里写页面的代码-->
    </div>

    <script>
        layui.use(['form', 'layedit', 'laydate', 'element', 'layer', 'upload'], function(){
            var form = layui.form,
                layer = layui.layer,
                element = layui.element,
                upload = layui.upload;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#img'
                , url: '/apiCommon/setImage'
                , field: 'layuiFile'
                , before: function (obj) {
                    //预读本地文件示例，不支持ie8
                    obj.preview(function (index, file, result, data) {
                        $('#demo1').css('display','block').attr('src', result); //链接（base64）
                    });
                }
                , done: function (res) {
                    //如果上传失败
                    if (res.code > 0) {
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    if(res.code == 0){
                        $('#imgurl').val(res.data.src);
                    }
                }
                , error: function () {
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function () {
                        uploadInst.upload();
                    });
                }
            });


            //监听提交，发送请求
            form.on('submit(add)', function(data){
                if(data.field.shopTypeStr==-1){
                    layer.alert('请选择品牌分类');
                    return false;
                }
                if(data.field.sbNameCn==""||data.field.sbNameCn==null){
                    layer.alert('请输入品牌中文名');
                    return false;
                }
                if(data.field.sbType==-1){
                    layer.alert('请选择品牌状态');
                    return false;
                }
                $.post("<%=basePath%>sbc/update",data.field,function(data){
                    // 获取 session
                    if(data.code!=200){
                        layer.alert(data.msg, {offset: 't',icon: 5});
                    }
                    if(data.code==200){
                        layer.alert(data.msg, {offset: 't',icon: 6});
                    }
                });
                return false;
            });

        });
    </script>
</body>
</html>
